package terra.network.packet;

import java.sql.Date;
import java.text.DateFormat;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

public class BigPing extends Packet{

	public long time;
	
	public BigPing(long curTime) {
		time = curTime;
	}

	public BigPing() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = ChannelBuffers.buffer(getLength());
		buf.writeByte(getId());
		buf.writeLong(time);
		for(int i = 0; i < 10000;i++)
			buf.writeByte(0);
		return buf;
	}

	@Override
	public int getLength() {
		return 9+10000;
	}

	@Override
	public byte getId() {
		return 127;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		time = buf.readLong();
		buf.readBytes(10000);
		return this;
	}

	public String toString() {
		return DateFormat.getInstance().format(new Date(time));
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}

}
